knitr::opts_chunk$set(echo = FALSE)
Description
Difference in means estimate of the ATE
Usage
ATEd(data)
Arguments
data: data frame containing cols y (positive outcome with zeros) and z (treatment).
Details
t.test() can be used as an alternative.
Value
difference in means estimate of the ATE
Description
Oracle model estimate of the ATE
Usage
ATEo(data)
Arguments
data: data frame containing cols y (positive outcome with zeros) and z (treatment).
Need to include s as well.
Details
This serves as a benchmark result under the ideal scenario where all strata are known. Often used
to compare with other analysis results.
Value
oracle estimate of ATE
Description
Computes parameter bounds to be used in L-BFGS-B mle optimization.
Usage
bounds_ls(data)
Arguments
data: data frame containing cols y (positive outcome with zeros) and z (treatment).
Details
Each strata much have at least three observations.
Value
The maximum and lowest possible values for segment proportions, mean, and variance.
Description
Computes the first order partial derivative of the log-likelihood for the latent stratification model,
with respect to every variable in the vector par.
Usage
gr_ll_ls(par, data, trans = FALSE)
Arguments
par: vector c(piA, piB, muA1, muA0, muB1, sigma), c(piA, piB/(1-piA), muA1,
muA0, muB1, sigma) if trans=TRUE.
data: data frame containing columns y (positive outcome with zeros) and z (treatment).
trans: boolean signifying if piB has been transformed.
Details
Sometimes piB is transformed to relative proportions from absolute proportions. This transformation
allows the reparameterization of the piA and piB to allow constraint bounds between 0 and 1
in the optimization procedure.
The output vector is named, each representing the gradient taken with respect to that variable in the
parameter.
Value
Gradient of the log-likilihood for the latent stratification model as a named vector.
Description
Computes the second order partial derivative with respect to each of the par variables, resulting in
a Hessian matrix.
Usage
hes_ll_ls(par, data, trans = FALSE)
Arguments
par: vector c(piA, piB, muA1, muA0, muB1, sigma), c(piA, piB/(1-piA), muA1,
muA0, muB1, sigma) if trans=TRUE.
data: data frame containing columns y (positive outcome with zeros) and z (treatment).
trans: boolean signifying if piB has been transformed.
Details
Sometimes piB is transformed to relative proportions from absolute proportions. This transformation
allows the reparameterization of the piA and piB to allow constraint bounds between 0 and 1
in the optimization procedure.
The returned Hessian is the second order derivative with respect to θ where θ is in the order (piA,
piB, muA1, muA0, muB1, sigma).
Value
Hessian matrix for the latent stratification model.
Description
Computes the log-likelihood for each of the four observational groups under the assumption of three
strata and common variance.
Usage
ll_ls(par, data, trans = FALSE)
Arguments
par: vector c(piA, piB, muA1, muA0, muB1, sigma), c(piA, piB/(1-piA), muA1,
muA0, muB1, sigma) if trans=TRUE.
data: data frame containing columns y (positive outcome with zeros) and z (treatment).
trans: boolean signifying if piB has been transformed.
Details
Sometimes piB is transformed to relative proportions from absolute proportions. This transformation
allows the reparameterization of the piA and piB to allow constraint bounds between 0 and 1
in the optimization procedure.
The log likelihoods are calculated based on equation 11-14 in the paper. Note that the equations
presented in the paper are for normal likelihood and for a single individual, thus corresponding
adjustments have been made in the code to calculate the log likelihood for the group.
Value
Log-likelihood for the latent stratification model.
Description
Variance-Covariance Matrix
Usage
ls_vcv(par, data, method)
Arguments
par: vector c(piA, piB, muA1, muA0, muB1, sigma).
data: data frame containing cols y (positive outcome with zeros) and z (treatment).
method method used for computation: score, hessian, robust, and bootstrap.
Details
Computes the variance-covariance matrix:
if method = "hessian" then the standard errors are computed by the numeric hessian
if method = "score" then standard errors are computed from the gradient
if method = "robust" then white robust standard errors are computed
if method = "bootstrap" then the standard errors are computed by bootstrap
Value
the variance-covariance matrix based on the specified method.
Description
Computes the maximum likelihood estimate for the latent stratification model, optionally takes
starting values in original parameter space.
Usage
mle_ls(data, start = NULL, starts = 1, vcv = "hessian", quiet = FALSE)
Arguments
data: data frame containing cols y (positive outcome with zeros) and z (treatment).
start: vector starting values for parameters c(piA, piB, muA1, muA0, muB1, sigma).
starts: number of starting values.
vcv: the variance-covariance matrix of the data, can be calculated using ls_vcv().
quiet: boolean controlling if the computation time should be printed after execution.
Details
If starts=1, then the optimization is run once from the starting values. If starts>1, then mle optimization
is done with multiple starting values, which are generated near the starting values.
The output is an ls model object, which can be called using summary() to show the ATE parameters,
their standard errors, and the maximum likelihood. To access the variance-covariance matrix, use
object$vcv.
Value
object containing the MLE results.
Description
Simulates the data from the latent stratification model with three strata.
Usage
sim_latent_strat(
n = 1e+05,
p = 0.5,
piA = 0.05,
piB = 0.1,
muA1 = 5,
muA0 = 4,
muB1 = 5,
sigma = 1
)
Arguments
n: total sample size, the default value is 100000.
p: treatment proportions, the default value is 0.5.
piA: proportion of strata A, the default value is 0.05.
piB: proportion of strata B, the default value is 0.10.
muA1: mean for strata A that received treatment, Z = 1, the default is 5.
muA0: mean for strata A that did not received treatment, Z = 0, the default value is 4.
muB1: mean for strata B that received treatment, Z = 1, the default value is 5.
sigma: variance for strata.
Details
The three strata are defined as:
A = positive under treatment and control.
B = positive under treatment only.
C = never positive.
The model assumes that strata D, which are those who are positive under control only, does not
exist. The model also assumes that all strata have the same variance.
Value
A list containing a data frame, a numeric value, and two vectors.
The data frame data contains the outcome variable y, treatment dummy z, strata, and the mean-centered
effects coded dummies for strata.
The numeric value ATE is the true average treatment effect.
The vector par consists of the true parameters of the simulated data.
Description
Computes the starting values for proportion, mean, and variance for optimization. The proportions
pi are transformed to relative sizes.
Usage
start_ls(data, rand = FALSE)
Arguments
data: data frame containing cols y (positive outcome with zeros) and z (treatment).
rand: boolean controlling whether random adjusted starting mean values are produced.
Details
By allowing rand=TRUE, the optim() in mle_ls() can be started in multiple places, providing random
adj values while remaining within reasonable bounds.
Value
starting values used for maximum-likelihood optimization.
Description
Estimates the standard error and the exponential of the standard error of ATE via the delta method.
Usage
varATEldelta(par, vcv)
Arguments
par: vector c(piA, piB, muA1, muA0, muB1, sigma).
vcv: variance-covariance matrix of the parameters, can be calculated using ls_vcv().
etails
The delta method estimates the variance by expanding the function of a random variable through
Taylor approximation, which can be expanded to vectorized calculations. For a more detailed explanation,
see https://www.stata.com/support/faqs/statistics/delta-method/.
Value
standard error of the average treatment effect.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.